#include <cstdio>
#include <algorithm>

using namespace std;

int num[105];

bool cmp(int a, int b) {
    int aa = a, bb = b;
    int suma = 0, sumb = 0;

    while(a) {
        suma += a % 10;
        a /= 10;
    }
    while(b) {
        sumb += b % 10;
        b /= 10;
    }

    if(suma == sumb) {
        return aa < bb;
    }

    return suma < sumb;
}

int main()
{
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &num[i]);
    }
    sort(num, num + N, cmp);

    for(int i = 0; i < N; i++) {
        if(i != N - 1) {
            printf("%d ", num[i]);
        } else {
            printf("%d\n", num[i]);
        }
    }

    return 0;
}
